package mo.leetcode_top;

import java.util.HashMap;
import java.util.Map;

public class L447 {

    public int numberOfBoomerangs(int[][] points) {
        int res = 0;
        for (int i = 0; i < points.length; i++) {
            int[] point = points[i];
            Map<Integer, Integer> distance2count = new HashMap<>();
            for (int j = 0; j < points.length; j++) {
                if (i == j) {
                    continue;
                }
                int x = point[0] - points[j][0];
                int y = point[1] - points[j][1];
                int distance = x * x + y * y;
                int count = distance2count.getOrDefault(distance, 0);
                count++;
                distance2count.put(distance, count);
            }
            for (int count : distance2count.values()) {
                res += count * (count - 1);
            }
        }
        return res;
    }

}
